<?php

// 测试管理员登录功能
$url = 'http://localhost:8000/api/auth/login';
$data = [
    'username' => 'admin',
    'password' => 'admin123'
];

// 初始化cURL
$ch = curl_init($url);

// 设置cURL选项
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, [
    'Accept: application/json',
    'Content-Type: application/x-www-form-urlencoded'
]);

// 执行请求
$response = curl_exec($ch);
$http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);

// 关闭cURL
curl_close($ch);

// 显示结果
echo "HTTP状态码: $http_code\n";
echo "响应内容: \n";
$decoded = json_decode($response);
echo json_encode($decoded, JSON_PRETTY_PRINT | JSON_UNESCAPED_UNICODE);
echo "\n";

// 检查用户数据
if ($decoded && isset($decoded->user)) {
    echo "\n用户信息验证:\n";
    echo "用户名: " . $decoded->user->username . "\n";
    echo "邮箱: " . $decoded->user->email . "\n";
    echo "是否管理员: " . ($decoded->user->is_admin ? "是" : "否") . "\n";
}